<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page import="com.hnas.core.util.PropertyUtil"%>
<%@page import="com.hnas.core.dto.DataBean"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>具体商家</title>
<script type="text/javascript">
</script>
</head>
<body>
	<!-- 标题 -->
	<div class="titleBar m_b_20">
		<div class="tit fl b_l_e74a5f">
			<h3 class="cn">具体商家</h3>
			<span class="en">merchant detail</span>
		</div>
		<div class="fr"></div>
	</div>
	<!-- end 标题 -->

	<form method="post" action="${pageContext.request.contextPath }/backend/merchantDetail/search" name="searchForm"  >
  	<input type="hidden" name="pageNo" value="${dto.pageNo}">
  	<input type="hidden" name="totalCount" value="${dto.totalCount}">
  	<input type="hidden" name="merchantId" id="searchMerchantId" value="${dto.merchantId}">
	<!-- 查询 -->
	 <div class="box_03 p_20 m_b_20">
		<table class="tb_style02" width="100%">
	        <tr>
                <th style="width:130px;">每页显示</th>
               	<td>
               		<input type="text" style="width:30px;" name="pageSize" id="pageSize" value="${dto.pageSize}" style="width:100px;" class="input_style2"/>
                </td>
                
                <th style="width:130px;"></th>
               	<td>
               		<input style="width:110px;" class="btn_brown02 m_r_12" type="button" name="searchData" id="searchData" value="查  询">
               		<input style="width:110px;" class="btn_brown02 m_r_12" type="button" name="addData" id="addData" value="添  加">
               		<input style="width:110px;" class="btn_brown02 m_r_12" type="button" id="goBack" value="返  回" onclick="history.back();return false;">
                </td>
	         </tr>
		</table>
	</div> 
	<!-- end 查询 -->
				
</form>

<div class="m_b_20">
	<table class="tb_style05" width="100%" style="table-layout:fixed;">
		<thead>
		<tr>
			<c:forEach items="${beans}" var="o">
			<c:if test="${o.display && !o.hidden}"><th>${o.title}</th></c:if>
			</c:forEach>
			<th>操作</th>
		</tr>
		</thead>
		<tbody>
			<c:forEach items="${pg.list}" var="o">
			<tr>
				<c:forEach items="${beans}" var="o1">
					<c:if test="${o1.display && !o1.hidden}">
					<td style="word-wrap:break-word;"><%=String.valueOf(PropertyUtil.getValue(pageContext.getAttribute("o"),((DataBean)pageContext.getAttribute("o1")).getField())).replace("false","否").replace("true","是")%></td></c:if>
				
				</c:forEach>
				<td>
				<a href="#" class="c_3366cc btn editData" detail_id = "${o.id}" id="editData">编辑</a>
				<a href="#" class="c_3366cc btn deleteData" detail_id = "${o.id}" id="deleteData">删除</a>
			</td>
			</tr>
			</c:forEach>
			
		</tbody>
	</table>
	<div class="searpage" align="right"><div>${pg.pageStr}</div></div><br/>
	<div class="editDataDiv" id="editDIV" title="${pageTitle}" style="display: none;" >
		<form action="#" id="editFm" method="post" name="editFm" class="editFm" ><!-- <input type="hidden" name="id" id="dealid" value=0> -->
			<table >
				<c:forEach items="${beans}" var="o">
					<c:choose>
						<c:when test="${o.hidden}">
							<input type="hidden" name="${o.field}" id="deal${o.fieldId}" value="">
						</c:when>
						<c:otherwise>
							<tr>
								<td width="26%" align="right"> 
									<label>${o.title}：</label>  
								</td>
								<c:if test="${o.tagType == 0}">
									<td> 
										<input type="text" name="${o.field}" id="deal${o.fieldId}" style="width:${o.length gt 0?o.length:200}px" <c:if test="${o.maxlength>0}">maxlength="${o.maxlength}"</c:if> <c:if test="${true == o.readonly}">readonly="readonly"</c:if>/>
										<c:if test="${not empty o.hint}">（${o.hint}）</c:if>
										<c:if test="${empty o.hint && o.dataType=='boolean'}">（1--是；0--否）</c:if>
										<c:if test="${!o.nullable}"><font color="red">*</font></c:if>
									</td>
								</c:if>
								<c:if test="${o.tagType == 1}">
									<td>
										<textarea name="${o.field}" id="deal${o.fieldId}" rows="3" style="width:${o.length gt 0?o.length:200}px" <c:if test="${o.maxlength>0}">maxlength="${o.maxlength}"</c:if> <c:if test="${true == o.readonly}">readonly="readonly"</c:if>></textarea>
										<c:if test="${not empty o.hint}">（${o.hint}）</c:if>
										<c:if test="${empty o.hint && o.dataType=='boolean'}">（1--是；0--否）</c:if>
										<c:if test="${!o.nullable}"><font color="red">*</font></c:if>
									</td>
								</c:if>
							</tr>
						</c:otherwise>
					</c:choose>
				</c:forEach>
				<tr>
	      			<td colspan="2">
	          			<p class="validateTips_deal" align="center"></p>
	      			</td>
	    		</tr>
			</table>
		</form>
	</div>
	
	
	
</div>
<%-- <script type="text/javascript" src="${pageContext.request.contextPath }/static/js/jquery.timepicker.js"></script> --%>
<script>
	function gotoJumpPage(){
		var jumpNum= $("#jumpNum").val();
		$("#search_page_size").val($("#id_page_size").val());
		gotoPage(jumpNum);
		return false;
	}
	$(function(){
		$("#searchData").click(function(){
			/** 校验输入页数是否非法  **/
			var pageSize=$("#pageSize").val();
			var reg = new RegExp("^[0-9]*$");
			if($.trim(pageSize)!=""){
				if(!reg.test($.trim(pageSize))){
					alert("每页显示数请输入非负整数");
	 				return false;
				}
			}
			if($.trim(pageSize)==""){
				alert("每页显示数不应许为空");
				return false;
			}
			doSubmit();
		});
		
	});
	function searchData(){
		/** 校验输入页数是否非法  **/
		var pageSize=$("#pageSize").val();
		var reg = new RegExp("^[0-9]*$");
		if($.trim(pageSize)!=""){
			if(!reg.test($.trim(pageSize))){
				alert("每页显示数请输入非负整数");
					return false;
			}
		}
		if($.trim(pageSize)==""){
			alert("每页显示数不应许为空");
			return false;
		}
		doSubmit();
	}
	
	$("#startDate").datepicker({
		dateFormat:'yy-mm-dd',
		changeYear: true,
		changeMonth: true,
		yearRange: "1900:2049" 
	});
	
	$("#endDate").datepicker({
		dateFormat:'yy-mm-dd',
		changeYear: true,
		changeMonth: true,
		yearRange: "1900:2049" 
	});	
	
	//锁定
	/* $(".disableData").click(function(){
		var id = $(this).attr("id");
		var valid = $(this).attr("data");
		$.ajax({
			url:"${pageContext.request.contextPath}/backend/account/updateAccount?id="+id+"&valid="+valid,
			type: 'POST',
			error: function(XMLHttpRequest, textStatus, errorThrown){
				 $.dialog.alert({title:"更新",content:"更新状态异常..."});
			},
			success: function(data){
				if("1" == data){
				 $.dialog.alert({title:"更新",content:"更新成功！"});	
					doSubmit();
				}
			}
		});
	}); */
	
	$("#addData").click(function(){
		doReset(document.editFm);
		$("#editDIV").dialog("open");
	});
	
	//编辑
	$(".editData").click(function(){
		var id = $(this).attr("detail_id");
		$.ajax({
			url:"${pageContext.request.contextPath}/backend/merchantDetail/show/"+id,
			type: 'POST',
			error: function(XMLHttpRequest, textStatus, errorThrown){
				 $.dialog.alert({title:"查看",content:"加载数据异常。"});
			},
			success: function(data){
				fillDIV(data);
			}
		});
		$("#editDIV").dialog("open");
	});
	
	function fillDIV(data){
		$("#dealid").val(data.id);
		<c:forEach items="${beans}" var="o">
			$("#deal${o.filterField}").val(data.${o.field});
		</c:forEach>
	}
	
	var editDivHeight = 350;
	var editDivWidth = 450;
	var isEditDivHeight = typeof myEditDivHeight == "undefined";
	var isEditDivWidth = typeof myEditDivWidth == "undefined";
	
	$("#editDIV").dialog({
		autoOpen : false,
		bgiframe: true, 
		height : isEditDivHeight?editDivHeight:myEditDivHeight,
		width : isEditDivWidth?editDivWidth:myEditDivWidth,
		modal : true,
		resizable :false,
		hide: '',
		show:'',
		zIndex:1000,
		buttons : {
			"保 存" : function() {
				var bValid = doValid();
				if(bValid){
					var isAdd = ($("#dealid").val() == null) || ($.trim($("#dealid").val()) == "")||($.trim($("#dealid").val()) == "0");
					var addUrl = "${pageContext.request.contextPath }/backend/merchantDetail/add";
					var updateUrl = "${pageContext.request.contextPath }/backend/merchantDetail/update";
					var URL = isAdd?addUrl:updateUrl;
					$("#dealmerchantId").val($("#searchMerchantId").val());
					$.ajax({
						url:URL,
						type: 'POST',
						data: $("#editFm").serialize(),
						error: function(XMLHttpRequest, textStatus, errorThrown){
						//alert('保存异常。' + textStatus + "/" + errorThrown);
						 $.dialog.alert({title:"保存",content:"保存异常"});
						},
						success: function(data){
							if(data.result==1) {
								$("#createDIV").dialog("close");
								if(isAdd){
									$.dialog.alert({title:"保存",content:"创建成功"});
								}else{
									$.dialog.alert({title:"保存",content:"修改成功"});
								}
								query();
							} else {
								if(isAdd){
									$.dialog.alert({title:"保存",content:"创建失败："+ data.errorMessage});	
								}else{
									$.dialog.alert({title:"保存",content:"修改失败："+ data.errorMessage});	
								}
								
							}
						}
					});  
				}
			}, 
			"取 消" : function() {
				$(this).dialog("close");			
			}
		},
		close : function() {
			$(this).dialog("close");
		}
			
	});
	
	function doValid(){
		var name = $("#dealname").val();
		if(name == null || $.trim(name) == ''){
			$.dialog.alert({title:"错误",content:"名称不能为空！",objCtrl:"#dealname"});
			return false;
		}
		return true;
	}
	
	$(".deleteData").click(function(){
		var id = $(this).attr("detail_id");
		$.dialog.confirm({title:"删除",content:"您确定要删除吗",callback:"deleteData('"+id+"');"});
		
	});
	function deleteData(id){
		$.ajax({
			url:"${pageContext.request.contextPath }/backend/merchantDetail/deleteById",
			type: 'POST',
			data:{'id':id},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				$.dialog.alert({title:"删除",content:"加载数据异常"});
			},
			success: function(data){
				if(data.result==1) {
					$.dialog.alert({title:"删除",content:"删除成功"});
					searchData();
				} else {
					$.dialog.alert({title:"删除",content:"删除失败:"+data.errorMessage});
				}
			}
		});
	}
	
</script>
</body>
</html>